package com.cn.algorithm01;

/**
 * @author hels
 * @version 1.0
 * @date 2021/11/1 17:26
 * https://leetcode.com/problems/maximum-depth-of-binary-tree
 */
public class Code20_MaximumDepthOfBinaryTree {
    // 创建一个二叉树节点对象
    public static class TreeNode{
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int v) {
            val = v;
        }
    }

    // 判断当前节点是否为空，不是空则继续递归
    public static int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }
}
